package cc.mrbird.common.utils;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;

public class HttpClientUtil {

	public static String doPost(String url, String jsonstr, String x_app_id, String x_app_key, String Authorization) {
		HttpClient httpClient = null;
		HttpPost httpPost = null;
		String result = null;
		try {
			httpClient = new SSLClient();
			// httpClient = HttpClients.createDefault();
			httpPost = new HttpPost(url);
			httpPost.addHeader("Content-Type", "application/json");
			httpPost.addHeader("X-APP-ID", x_app_id);
			httpPost.addHeader("X-APP-KEY", x_app_key);
			// httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
			// httpPost.setHeader("Accept", "application/json");
			// httpPost.setHeader("Authorization", Authorization);
			StringEntity se = new StringEntity(jsonstr);
			// se.setContentType("text/json");
			// se.setContentEncoding(new BasicHeader("Content-Type", "application/json"));
			// se.setContentEncoding(new BasicHeader("Content-Type",
			// "application/json;charset=UTF-8"));
			httpPost.setEntity(se);
			System.out.println("开始访问----------");
			HttpResponse response = httpClient.execute(httpPost);
			if (response != null) {
				HttpEntity resEntity = response.getEntity();
				if (resEntity != null) {
					result = EntityUtils.toString(resEntity, "utf-8");
				}
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		}
		System.out.println("接收到的数据:" + result);
		return result;
	}

	public static String doPostIcnoc(String jsonstr) {
		HttpClient httpClient = null;
		HttpPost httpPost = null;
		String result = null;
		try {
			httpClient = new SSLClient();
			httpPost = new HttpPost("http://137.32.44.188:28766/eop/hnwp/dlopen/sjxf/JTToProvicePropGetInterface");
			httpPost.addHeader("Content-Type", "application/json");
			httpPost.addHeader("X-APP-ID", "41d0003d053e17dfc015c834bcac2042");
			httpPost.addHeader("X-APP-KEY", "ac31dbf671de01b68705d0a22124adfb");
			StringEntity se = new StringEntity(jsonstr);
			httpPost.setEntity(se);
			System.out.println("开始访问----------");
			HttpResponse response = httpClient.execute(httpPost);
			if (response != null) {
				HttpEntity resEntity = response.getEntity();
				if (resEntity != null) {
					result = EntityUtils.toString(resEntity, "utf-8");
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		System.out.println("接收到的数据:" + result);
		return result;
	}
}
